package com.example.sync.handler.impl;

import com.example.mq.listener.SysMQMessageListener;
import com.example.sync.handler.impl.wrap.SysMQRetryMessage;
import com.example.sync.po.SysASyncJob;
import com.example.utils.SerializableUtils;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/*
 * @className: SysMQMessageRetryHandler
 * @author: chentao
 * @date: 2025/3/25 上午8:06
 * @Version: 1.0
 * @description: mq消息消费重试
 */
@Service
public class SysMQMessageRetryHandler extends SysAbstractHandler {

    public static final String TYPE = "mq_retry";

    @Resource
    private ApplicationContext applicationContext;

    @Override
    public String getType() {
        return TYPE;
    }

    @Override
    public void handle(SysASyncJob sysASyncJob) throws Exception {
        SysMQRetryMessage sysMQRetryMessage = (SysMQRetryMessage) SerializableUtils.deserializeFromString(sysASyncJob.getTargetContent(), SysMQRetryMessage.class);
        SysMQMessageListener sysMQMessageListener = (SysMQMessageListener) applicationContext.getBean(sysMQRetryMessage.getBeanName());
        sysMQMessageListener.onMessage(sysMQRetryMessage.getMessage());
    }
}
